package com.charmzenus.it.member.controller;

import com.charmzenus.it.common.dto.response.BaseResponseDTO;
import com.charmzenus.it.feign.MemberClient;
import com.charmzenus.it.feign.OrderClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/test")
public class TestController {


    @Autowired
    RestTemplate restTemplate;

//    @Autowired
//    OrderClient orderClient;

//    @Autowired
//    MemberClient memberClient;

    @PostMapping("/test")
    public BaseResponseDTO<String> test(String message) {

        BaseResponseDTO<String> tmp = new BaseResponseDTO<>();
        System.out.println(message);

        MultiValueMap<String, String> requestParam = new LinkedMultiValueMap<>();
        requestParam.set("orderName", "IphoneXs");

        // 直接写死url
        BaseResponseDTO<String> baseResponseDTO = restTemplate.postForObject("http://127.0.0.1:9091/order/getList", requestParam, BaseResponseDTO.class);

        System.out.println(baseResponseDTO.toString());
        return tmp;
    }


    @PostMapping("/test2")
    public BaseResponseDTO<String> test2() {
        BaseResponseDTO<String> temp = new BaseResponseDTO<>();

        MultiValueMap<String, String> requestParam = new LinkedMultiValueMap<>();
        requestParam.set("orderName", "IphoneXs");
        // 直接写死url
        BaseResponseDTO<String> baseResponseDTO = restTemplate.postForObject("http://ORDER/order/getList",
                requestParam, BaseResponseDTO.class);
        System.out.println(baseResponseDTO.toString());
        return temp;
    }


    @GetMapping("/test3")
    public String test3() {

//        String s = orderClient.orderTest("Xiao ==> ");

//        System.out.println(s);
        return "hello";
    }


    @GetMapping("/orderTest")
    public BaseResponseDTO<String> orderTest( String name) {
        BaseResponseDTO<String> tmp = new BaseResponseDTO<>();
        tmp.setData("hello Feign  order   ========= ");
        System.out.println(name);

        return tmp;
    }
}
